import useDictStore from '@/store/modules/dict'
import { getDicts } from '@/api/system/dict/data'

/**
 * 获取字典数据
 */
export function useDict(...args) {
  const res = {}
  return new Promise((resolve, reject) => {
    Promise.all(args.map(dictType => getDicts(dictType).then(resp => {
      res[dictType] = resp.data.map(p => ({ 
        label: p.dictLabel, 
        value: p.dictValue, 
        elTagType: p.listClass,
        elTagClass: p.cssClass
      }))
      return res[dictType]
    }))).then(() => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}